{{define "blog/article/index.html"}} {{ template "header" . }}

<body class="gray-bg">
    <div class="wrapper wrapper-content">
        <div class="ibox-title">
            系统管理 / 帮助中心管理
        </div>
        <form role="form" class="form-inline">
            <div class="ibox-title">
                <div class="form-group">
                    <label for="title" class="sr-only">类别名称</label>
                    <input type="text" name="title" placeholder="请输入标题" class="form-control" value="{{.title}}">
                </div>
                <div class="form-group">
                    <select class="form-control" id="lang_type">
                        <option value="0">全部语言</option>
                        <option value="1" {{if eq .langType 1}} selected {{end}}>中文</option>
                        <option value="2" {{if eq .langType 2}} selected {{end}}>英语</option>
                    </select>
                </div>
                <div class="form-group">
                    {{$tid := .articleTypeId}}
                    <select class="form-control" id="article_type" required>
                        <option value="0">全部分类</option>
                        {{range .type}}
                            <option value="{{.ID}}" {{if eq .ID $tid}} selected {{end}}>{{.TypeName}}</option>
                        {{end}}
                    </select>
                </div>
                <div class="btn btn-white" onclick="search()"><i class="fa fa-search"></i> 搜索</div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <input type="hidden" name="token" value="{{ .token }}">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <a href="/blog/article/add">
                                <button type="button" class="btn btn-primary">
                                    添 加
                                </button>
                            </a>
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>排序</th>
                                            <th>标题</th>
                                            <th>语言类型</th>
                                            <th>所属分类</th>
                                            <th>创建时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {{range .list}}
                                        <tr>
                                            <td>{{.id}}</td>
                                            <td>{{.sort_num}}</td>
                                            <td>{{.title}}</td>
                                            <td>{{if eq .lang_type 1 }} 中文 {{else}} 英文 {{end}}</td>
                                            <td>{{.type_name}}</td>
                                            <td>{{.created_at}}</td>
                                            <td>
                                                <a href="/blog/article/edit?id={{.id}}">
                                                    <button type="button" class="btn btn-xs btn-primary">编辑
                                                    </button>
                                                </a>
                                                <a onclick="del({{.id}})">
                                                    <button type="button" class="btn btn-xs btn-warning">删除
                                                    </button>
                                                </a>
                                            </td>
                                        </tr>
                                        {{end}}

                                    </tbody>
                                </table>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </form>

        <div id="pagination"></div>
    </div>
</body>

{{ template "footer" . }}
<script>
    var page = {{.page}}
    var pageSize = {{.pageSize}}
    var total = {{.total}}


    var title = $("input[name='title']").val()
    var lang_type = $("#lang_type").val()
    var article_type_id = $("#article_type").val()

    // 将搜索条件(对象)传入分页器
    var obj = {title, lang_type,  article_type_id}
    console.log('objx', obj)
    var p = new Pagination("#pagination", {page, pageSize, total},obj)

    function search() {
        var title = $("input[name='title']").val();
        var lang_type = $("#lang_type").val()
        var article_type_id = $("#article_type").val()

        // 将搜索条件(对象)传入分页器
        var obj = {title, lang_type,  article_type_id}
        console.log('objx', obj)
        p.withOptions(obj)

    }

    function del(id) {
        layer.confirm("确定删除?", {
            btn: ['确定', '取消']
        }, function() {
            var token = $("input[name='token']").val();
            $.post("/blog/article/del", {
                id: id,
                token: token
            }, function(jsonData) {
                // var jsonData = $.parseJSON(res);
                if (jsonData.status !== 200 && jsonData.status !== 20023) {
                    if (jsonData.status !== 20007) {
                        $("input[name='token']").val(jsonData.data);
                    }
                    layer.msg(jsonData.message, {
                        icon: 2,
                        time: 1200,
                        title: "提示"
                    });
                } else if (jsonData.status === 20023) {
                    window.location.href = "/nopermission";
                } else {
                    layer.msg(jsonData.message, {
                        icon: 1,
                        time: 1000,
                        title: "提示",
                        end: function() {
                            window.location.href = "/blog/article";
                        }
                    });
                }
            });
        });
    }
</script>
{{end}}